package config;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice  //另有@RestControllerAdvice
public class GlobalExceptionHandler {

    //Exception.class表示处理全局异常
    @ExceptionHandler(Exception.class)
    public String myError(Exception e, Model model) {
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.addObject("msg", e.getMessage());
//        modelAndView.setViewName("myerror");
//        return modelAndView;
        model.addAttribute("msg", e.getMessage());
        return "myerror";
    }
}